#!/usr/bin/python
# Filename: try_except.py

import sys
import time

class ShortInputException(Exception):
	'''A user-defined exception class.'''
	def __init__(self, length, atleast):
		Exception.__init__(self)
		self.length = length
		self.atleast = atleast

try:
	s = raw_input('Enter something --> ')
	if len(s) < 3:
		raise ShortInputException(len(s), 3)  
        #we use raise to raise a exception

except EOFError:   #occurred by CTRL+D
	print '\nWhy did you do an EOF on me?'
	sys.exit()   #exit the program
except ShortInputException, x:
	print 'ShortInputException: The input was of length %d, \
was expecting at least %d' % (x.length, x.atleast)
else:
	print 'No exception was raised.'

finally:
	time.sleep(2)
	print 'Done'
